package com.suixinsanren.design.compound.study.demo05;

/**
 * 橡皮鸭，呱呱叫的时其实是吱吱叫
 */
public class RubberDuck implements Quackable {

    private final Observable observable;

    public RubberDuck() {
        this.observable = new Observable(this);
    }

    @Override
    public void quack() {
        System.out.println("Squeak");
        observable.notifyObservers();
    }

    @Override
    public void registerObserver(Observer duck) {
        observable.registerObserver(duck);
    }

    @Override
    public void notifyObservers() {
        observable.notifyObservers();
    }

    @Override
    public String toString() {
        return "Rubber Duck";
    }
}
